<?php

class AdministratorForm extends CFormModel
{
	public $fname;
	public $sname;
	public $username;
	public $password;
	public $email;

	public function rules()
	{
		return array(
			// name, email, subject and body are required
			array('fname, sname, username, password, email', 'required'),
			array('fname, sname, username, password, email', 'safe'),
		);
	}

	public function attributeLabels()
	{
		return array(
			'fname'=>'First name',
			'sname'=>'Second name',
			'username'=>'Username',
			'password'=>'Password',
			'email'=>'Email',
		);
	}
	
	public function insertAdministrator()
	{
		$model = new User();
		$model->setAttribute('active', 1);
		$model->setAttribute('fname', $this->fname);
		$model->setAttribute('sname', $this->sname);
		$model->setAttribute('username', $this->username);
		$model->setAttribute('password', $this->password);
		$model->setAttribute('email', $this->email);
		$model->setAttribute('isAdmin', 1);
		
		$model->setPassword();
		$model->save();
	}
}